#!/usr/bin/ruby -Ku

require 'rubygems'
require 'json'

datas = []
idxs = []

i = 0
open('datas.csv') do |f|
    while l = f.gets
        arr = l.split(",")
        p arr
        if i != 0 then
            idxs.push :id => arr[0], :name => arr[1], :image_url => arr[3]
            datas.push :id => arr[0], :name => arr[1], :text => arr[2], :image_url => arr[3]
        end
        i += 1
    end
end


idxf = open("index.json", "w")
idxf.write idxs.to_json
idxf.close

datas.each do |data|
    fname = data[:id]+".json"
    df = open(fname, "w")
    df.write data.to_json
    df.close
end
